package com.jevons.geo_lib.geojson.adapter;

import com.google.gson.Gson;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.mapbox.geojson.BoundingBox;
import com.mapbox.geojson.CoordinateContainer;
import com.mapbox.geojson.MultiPolygon;
import com.mapbox.geojson.Point;

import java.io.IOException;
import java.util.List;

/**
 * Copyright 2020 JxGIS
 *
 * @file MultiPolygonGsonTypeAdapter
 * @auth linaisheng
 * Created on 2022/7/13.
 * Description：
 */
final class MultiPolygonTypeAdapter
        extends BaseGeometryTypeAdapter<MultiPolygon, List<List<List<Point>>>> {

    MultiPolygonTypeAdapter(Gson gson) {
        super(gson, new ListofListofListOfPointCoordinatesTypeAdapter());
    }

    @Override
    public void write(JsonWriter jsonWriter, MultiPolygon object) throws IOException {
        writeCoordinateContainer(jsonWriter, object);
    }

    @Override
    public MultiPolygon read(JsonReader jsonReader) throws IOException {
        return (MultiPolygon) readCoordinateContainer(jsonReader);
    }

    @Override
    CoordinateContainer<List<List<List<Point>>>>
    createCoordinateContainer(String type, BoundingBox bbox, List<List<List<Point>>> coords) {
        return MultiPolygon.fromLngLats(coords, bbox);
    }
}